<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>商品管理</title>
    <base th:href="${#request.getContextPath()} + '/'">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->

    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">

    <script type="text/javascript">
        function switchSysBar() {
            var ssrc = document.all("imgs1").src;
            ssrc = ssrc.substring(ssrc.lastIndexOf("/") + 1, ssrc.length);
            if (ssrc == "main_55.gif") {
                document.all("imgs1").src = "main_55_1.gif";
                document.all("frmLefts2").style.display = "none";
            } else {
                document.all("imgs1").src = "main_55.gif";
                document.all("frmLefts2").style.display = "";
            }
        }
    </script>

    <!-- 树组件start -->
    <script type="text/javascript" src="js/jquery-3.1.1.js"></script>
    <link rel="stylesheet" href="zTreeStyle.css" type="text/css">
    <script type="text/javascript" src="jquery.ztree.core-3.5.js"></script>
    <link type="text/css" rel="stylesheet" href="public.css"></link>

    <!-- 系统共用js文件 -->
    <link rel="stylesheet" type="text/css" href="ymPrompt.css"/>
    <script type="text/javascript" src="ymPrompt.js"></script>
    <script type="text/javascript" src="public.js"></script>
    <script type="text/javascript" src="ServerClock.js"></script>
    <script type="text/javascript" src="table.js"></script>
    <script type="text/javascript" src="WdatePicker.js"></script>

    <script type="text/javascript">
        var setting = {
            check: {
                enable: false
            },
            data: {
                simpleData: {
                    enable: true
                }
            }
        };




    </script>


</head>

<body>
<div class="container-fluid" id="tm">
    <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
        <tbody>
        <tr>
            <td width="200" id="frmLefts2" valign="top" align="top" style="border-right: solid 1px #D6E3F3;">


                <!--树结构的目录-->
                               <ul id="treeDemo" class="ztree"></ul>


            </td>

            <td width="6" id="codeTitle" style="width:6px;" valign="middle" bgcolor="#F4F8EE" onclick="switchSysBar()">
					<span class="navPoint" id="switchPoint" title="关闭/打开左栏">
					<img src="main_55.gif" style="cursor:hand;margin-top:8px;" name="imgs1" width="6" height="40"
                         id="imgs1"> </span>
            </td>

            <td>
                <table width="100%" border="0" cellspacing="6" cellpadding="0"
                       style="border-collapse: separate; border-spacing: 6px;">
                    <tr valign="top">

                        <td>
                            <table width="100%" border="0" cellspacing="0" cellpadding="6"
                                   class="blockTable">
                                <tr>
                                    <td valign="middle" class="blockTd">
                                        <img src="http://javen666.com:8080/fxmall/Framework/Icons/icon012a6.gif"/>
                                        商品信息列表
                                    </td>
                                </tr>
                                <tr>
                                    <td style="padding: 0 8px 4px;">
                                        <a href='javascript:void(0);' ztype='zPushBtn' class='zPushBtn'
                                           hidefocus='true' tabindex='-1' onselectstart='return false'
                                           onClick="add();return false;"><img
                                                src="http://javen666.com:8080/fxmall/Framework/Icons/icon003a2.gif"/><b>新增&nbsp;</b>
                                        </a>

                                        <a href='javascript:void(0);' ztype='zPushBtn' class='zPushBtn'
                                           hidefocus='true' tabindex='-1' onselectstart='return false'
                                           onClick="toped('toped');return false;"><img
                                                src="http://javen666.com:8080/fxmall/Framework/Icons/icon400a4.gif"/><b>置顶&nbsp;</b>
                                        </a>
                                        <a href='javascript:void(0);' ztype='zPushBtn' class='zPushBtn'
                                           hidefocus='true' tabindex='-1' onselectstart='return false'
                                           onClick="toped('ctoped');return false;"><img
                                                src="http://javen666.com:8080/fxmall/Framework/Icons/icon400a2.gif"/><b>取消置顶&nbsp;</b>
                                        </a>
                                        <a href='javascript:void(0);' ztype='zPushBtn' class='zPushBtn'
                                           hidefocus='true' tabindex='-1' onselectstart='return false'
                                           onClick="recomed('recomed');return false;"><img
                                                src="http://javen666.com:8080/fxmall/Framework/Icons/icon401a17.gif"/><b>推荐&nbsp;</b>
                                        </a>
                                        <a href='javascript:void(0);' ztype='zPushBtn' class='zPushBtn'
                                           hidefocus='true' tabindex='-1' onselectstart='return false'
                                           onClick="recomed('crecomed');return false;"><img
                                                src="http://javen666.com:8080/fxmall/Framework/Icons/icon401a18.gif"/><b>取消推荐&nbsp;</b>
                                        </a>
                                        <a href='javascript:void(0);' ztype='zPushBtn' class='zPushBtn'
                                           hidefocus='true' tabindex='-1' onselectstart='return false'
                                           onClick="upStore(1);return false;"><img
                                                src="http://javen666.com:8080/fxmall/Framework/Icons/icon043a2.gif"/><b>上架&nbsp;</b>
                                        </a>
                                        <a href='javascript:void(0);' ztype='zPushBtn' class='zPushBtn'
                                           hidefocus='true' tabindex='-1' onselectstart='return false'
                                           onClick="upStore(0);return false;"><img
                                                src="http://javen666.com:8080/fxmall/Framework/Icons/icon043a3.gif"/><b>下架&nbsp;</b>
                                        </a>
                                        <a href='javascript:void(0);' ztype='zPushBtn' class='zPushBtn'
                                           hidefocus='true' tabindex='-1' onselectstart='return false'
                                           onClick="del();return false;"><img
                                                src="http://javen666.com:8080/fxmall/Framework/Icons/icon003a3.gif"/><b>删除&nbsp;</b>
                                        </a>
                                        关键词:
                                        <input name="searchText" type="text" id="searchText" onkeydown="enterSubmit();"
                                               class="ipt_style" value="">
                                        <input type="hidden" name="depart_id" id="depart_id" value="">
                                        <input type="button" name="sb" id="sb" class="btn_style" value="查询"
                                               onclick="return search();">
                                    </td>
                                </tr>
                                <tr>
                                    <td style="padding-top: 0px; padding-left: 6px; padding-right: 6px; padding-bottom: 8px;">
                                        <table width="100%" cellpadding="2" cellspacing="1"
                                               class="dataTable" sortstring="" id="dg1" page="true" size="0"
                                               multiselect="true" autofill="true" scroll="false" lazy="false"
                                               cachesize="0">
                                            <tr ztype="head" class="dataTableHead">
                                                <td width="5%" align="center">
                                                    序 号
                                                </td>
                                                <td width="3%" align="center" ztype="selector" field="id">
                                                    <input type='checkbox' value='*' id='dg1_AllCheck'
                                                           onclick="DataGrid.onAllCheckClick('dg1')"/>
                                                </td>
                                                <td align="center" width="15%">
                                                    <b>商品名称</b>
                                                </td>
                                                <td align="center" width="15%">
                                                    <b>商品图片</b>
                                                </td>
                                                <td align="center" width="10%">
                                                    <b>商户名称</b>
                                                </td>
                                                <td align="center" width="10%">
                                                    <b>是否置顶</b>
                                                </td>
                                                <td align="center" width="12%">
                                                    <b>是否推荐</b>
                                                </td>
                                                <td align="center" width="15%">
                                                    <b>价格</b>
                                                </td>
                                                <td align="center" width="10%">
                                                    <b>状态</b>
                                                </td>
                                                <td align="center" width="10%">
                                                    <b>排序</b>
                                                </td>
                                            </tr>


                                            <tr th:each="g,goods:${pageBean.wxbGoods}" height="35" id="14886110_tr" ondblclick="edit('14886110');"
                                                onclick="DataGrid.onRowClick(this,event);" style="background:#ffffff">


                                                <td align="center" th:text="${goods.count}">
                                                    1
                                                </td>
                                                <td align="center" onclick="DataGrid.onSelectorClick(this,event);"
                                                    ondblclick="stopEvent(event);">
                                                    <input type='checkbox' name='dg1_RowCheck' th:id="'dg1_RowCheck'+${goods.count}"
                                                           th:value='${g.goodId}'>
                                                </td>

                                                <td align="center">
                                                    <a href="#" onClick="edit('14886110')" th:text="${g.goodName}">asdadsa</a>
                                                </td>

                                                <td align="center" height="100px">


                                                    <img th:src="${g.goodPic}" th:attr="src=${g.goodPic}"
                                                         style="width:150px;height:100px;"/>

                                                </td>

                                                <td align="center" th:text="${g.customerName}">
                                                    qq123456
                                                </td>

                                                <td align="center">


                                                    <span class="label label-sm label-primary"><span th:if="${g.toped==0}">未置顶</span><span th:if="${g.toped==1}">置顶</span></span>


                                                </td>

                                                <td align="center">


                                                <span class="label label-sm label-grey">

                                                    <span th:if="${g.recomed==0}">未推荐</span>
                                                    <span th:if="${g.recomed==1}">推荐</span>

                                                </span>

                                                </td>
                                                <td align="center">
                                                    1|
                                                </td>
                                                <td align="center" th:id="'sj'+${g.goodId}">
                                                    <font color="blue" th:if="${g.state==0}">待上架</font>
                                                    <font color="green" th:if="${g.state==1}">已上架</font>


                                                </td>
                                                <td align="center">
                                                    11
                                                </td>
                                            </tr>



                                            <tr>
                                                <td colspan="10" align="center" id="dg1_PageBar" class="pagebg">
                                                    <div style='float: right; font-family: Tahoma;' class="flickr">



                                                        &lt;!&ndash;
                                                        <span  class="current">1</span>&ndash;&gt;
                                                            <span th:each="page:${#numbers.sequence(1,pageBean.tatolPage)}">
                                                                <span class="current"  th:text="${page}" th:onclick="'javascript:goes(\''+${page}+'\')'">1</span>
<!--                                                                <span th:if="${page == pageBean.tatolPage}"  class="current"  th:text="${page}" onclick="goes(${pageBean.tatolPage})">1</span>-->
                                                            </span>


                                                    </div>

                                                    <div style='float: left; font-family: Tahoma'>
                                                        共 <span th:text="${pageBean.tatolSize}">4</span> 条记录，
                                                        每页 <span th:text="${pageBean.pageSize}">5</span>  条，共
                                                        <span th:text="${pageBean.tatolPage}">4</span> 页
                                                    </div>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>

            </td>
        </tr>
        </tbody>
    </table>
</div>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>

<script>
    $.get("goods/type",function (data) {
        var ztree;
        var zNodes = data;
        if (zNodes == null || zNodes == "") {
            Exceptalert("查询分类数据出错了哦！", null, false);
        }
        ztree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        //var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        type = {"Y": "", "N": "s"};
        ztree.setting.check.chkboxType = type;

    });

    //flag用来判断当前是上架还是下架
    function upStore(flag) {
        var checkBookArray = $("input[name='dg1_RowCheck']");

        var checkedAll="";
        for (let i=0;i<checkBookArray.length;i++) {

            var checked = checkBookArray[i].checked;

            var value = checkBookArray[i].getAttribute("value");

            if (checked) {
                checkedAll=checkedAll+value+","
            }

        }
        var len = checkedAll.length-1;
        var param = checkedAll.substring(0,len);


        $.post("goods/upstore-downstore",{flag:flag,ids:param},function (data) {
            //alert(data.code);
            if (data.code==0) {
                for (let i=0;i<checkBookArray.length;i++) {
                    var checked = checkBookArray[i].checked;
                    if (checked) {
                        var _id = checkBookArray[i].getAttribute("value");
                        if (flag == 1) {
                            $("#sj" + _id).html("<font color=\"green\">已上架</font>")
                        } else {
                            $("#sj" + _id).html("<font color=\"blue\">待上架</font>")
                        }
                    }

                }
            }
        });
    }

    /*function toNextPage(url) {
        $("#right").load(url);
    }*/
    function goes(currentPage) {
        //window.location.href="page/goods-list.html?currentPage="+currentPage;
        //$("#frmRight2").load("page/goods-list.html?currentPage="+currentPage);
        $("#tm").load("page/goods-list.html?currentPage="+currentPage);
    }
</script>
</body>
</html>